from flask import Flask, render_template,request

app = Flask(__name__)

# 假设我们有以下消息列表
messages = []

@app.route('/')
def home():
    sorted_messages = sorted(messages, key=lambda x: x['compare'], reverse=True)
    return render_template('home2.html', messages=sorted_messages)

@app.route('/post_msg',methods = ['POST'])
def add_msg():
    data = request.get_json()
    messages.append(data)
    return data

@app.route('/get_new_messages')
def get_new_messages():
    sorted_messages = sorted(messages, key=lambda x: x['compare'], reverse=True)
    return render_template('messages.html', messages=sorted_messages)


if __name__ == "__main__":
    app.run(debug=True,port=5400)